/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jpa.entities;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author issao
 */
@Entity
@Table(name = "paciente")
@NamedQueries({
    @NamedQuery(name = "Paciente.findAll", query = "SELECT p FROM Paciente p"),
    @NamedQuery(name = "Paciente.findByIdPaciente", query = "SELECT p FROM Paciente p WHERE p.idPaciente = :idPaciente"),
    @NamedQuery(name = "Paciente.findByRg", query = "SELECT p FROM Paciente p WHERE p.rg = :rg"),
    @NamedQuery(name = "Paciente.findByCpf", query = "SELECT p FROM Paciente p WHERE p.cpf = :cpf"),
    @NamedQuery(name = "Paciente.findByOrgaoEmissor", query = "SELECT p FROM Paciente p WHERE p.orgaoEmissor = :orgaoEmissor"),
    @NamedQuery(name = "Paciente.findByUf", query = "SELECT p FROM Paciente p WHERE p.uf = :uf"),
    @NamedQuery(name = "Paciente.findByCtps", query = "SELECT p FROM Paciente p WHERE p.ctps = :ctps"),
    @NamedQuery(name = "Paciente.findBySerieCtps", query = "SELECT p FROM Paciente p WHERE p.serieCtps = :serieCtps"),
    @NamedQuery(name = "Paciente.findByUfCtps", query = "SELECT p FROM Paciente p WHERE p.ufCtps = :ufCtps"),
    @NamedQuery(name = "Paciente.findByNome", query = "SELECT p FROM Paciente p WHERE p.nome = :nome"),
    @NamedQuery(name = "Paciente.findByEndereco", query = "SELECT p FROM Paciente p WHERE p.endereco = :endereco"),
    @NamedQuery(name = "Paciente.findByBairro", query = "SELECT p FROM Paciente p WHERE p.bairro = :bairro"),
    @NamedQuery(name = "Paciente.findByCidade", query = "SELECT p FROM Paciente p WHERE p.cidade = :cidade"),
    @NamedQuery(name = "Paciente.findByCep", query = "SELECT p FROM Paciente p WHERE p.cep = :cep"),
    @NamedQuery(name = "Paciente.findByDataNascimento", query = "SELECT p FROM Paciente p WHERE p.dataNascimento = :dataNascimento"),
    @NamedQuery(name = "Paciente.findByEstadoCivil", query = "SELECT p FROM Paciente p WHERE p.estadoCivil = :estadoCivil"),
    @NamedQuery(name = "Paciente.findBySexo", query = "SELECT p FROM Paciente p WHERE p.sexo = :sexo"),
    @NamedQuery(name = "Paciente.findByTelefone", query = "SELECT p FROM Paciente p WHERE p.telefone = :telefone")})
public class Paciente implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * Utilizado para bean binding
     * adicionado por Issao
     */
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    /**
     * 
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "id_paciente")
    private Integer idPaciente;
    @Size(max = 15)
    @Column(name = "rg")
    private String rg;
    @Size(max = 11)
    @Column(name = "cpf")
    private String cpf;
    @Size(max = 45)
    @Column(name = "orgao_emissor")
    private String orgaoEmissor;
    @Size(max = 2)
    @Column(name = "uf")
    private String uf;
    @Size(max = 20)
    @Column(name = "ctps")
    private String ctps;
    @Size(max = 5)
    @Column(name = "serie_ctps")
    private String serieCtps;
    @Size(max = 2)
    @Column(name = "uf_ctps")
    private String ufCtps;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 200)
    @Column(name = "nome")
    private String nome;
    @Size(max = 200)
    @Column(name = "endereco")
    private String endereco;
    @Size(max = 100)
    @Column(name = "bairro")
    private String bairro;
    @Size(max = 100)
    @Column(name = "cidade")
    private String cidade;
    @Size(max = 10)
    @Column(name = "cep")
    private String cep;
    @Size(max = 1)
    @Column(name = "estado_civil")
    private String estadoCivil;
    @Column(name = "data_nascimento")
    @Temporal(TemporalType.DATE)
    private Date dataNascimento;
    @Size(max = 1)
    @Column(name = "sexo")
    private String sexo;
    @Size(max = 20)
    @Column(name = "telefone")
    private String telefone;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "fkPaciente")
    private Collection<FuncaoPaciente> funcaoPacienteCollection;

    public Paciente() {
    }

    public Paciente(Integer idPaciente) {
        //this.idPaciente = idPaciente;
        Integer old = this.idPaciente;
        this.idPaciente = idPaciente;
        changeSupport.firePropertyChange("idPaciente", old, idPaciente);
    }

    public Paciente(Integer idPaciente, String nome) {
        this.idPaciente = idPaciente;
        this.nome = nome;
    }

    public Integer getIdPaciente() {
        return idPaciente;
    }

    public void setIdPaciente(Integer idPaciente) {
        this.idPaciente = idPaciente;
    }

    public String getRg() {
        return rg;
    }

    public void setRg(String rg) {
        String oldRg = this.rg;
        this.rg = rg;
        changeSupport.firePropertyChange("rg", oldRg, rg);
    }

    public String getCpf() {
        return cpf;
    }

    public void setCpf(String cpf) {
        String old = this.cpf;
        this.cpf = cpf;
        changeSupport.firePropertyChange("cpf", old, cpf);
    }

    public String getOrgaoEmissor() {
        return orgaoEmissor;
    }

    public void setOrgaoEmissor(String orgaoEmissor) {
        String old = this.orgaoEmissor;
        this.orgaoEmissor = orgaoEmissor;
        changeSupport.firePropertyChange("orgaoEmissor", old, orgaoEmissor);
    }

    public String getUf() {
        return uf;
    }

    public void setUf(String uf) {
        String old = this.uf;
        this.uf = uf;
        changeSupport.firePropertyChange("uf", old, uf);
    }

    public String getCtps() {
        return ctps;
    }

    public void setCtps(String ctps) {
        String old = this.ctps;
        this.ctps = ctps;
        changeSupport.firePropertyChange("ctps", old, ctps);
    }

    public String getSerieCtps() {
        return serieCtps;
    }

    public void setSerieCtps(String serieCtps) {
        String old = this.serieCtps;
        this.serieCtps = serieCtps;
        changeSupport.firePropertyChange("serieCtps", old, serieCtps);
    }

    public String getUfCtps() {
        return ufCtps;
    }

    public void setUfCtps(String ufCtps) {
        String old = this.ufCtps;
        this.ufCtps = ufCtps;
        changeSupport.firePropertyChange("ufCtps", old, ufCtps);
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        String old = this.nome;
        this.nome = nome;
        changeSupport.firePropertyChange("nome", old, nome);
    }

    public String getEndereco() {
        return endereco;
    }

    public void setEndereco(String endereco) {
        String old = this.endereco;
        this.endereco = endereco;
        changeSupport.firePropertyChange("endereco", old, endereco);
    }

    public String getBairro() {
        return bairro;
    }

    public void setBairro(String bairro) {
        String old = this.bairro;
        this.bairro = bairro;
        changeSupport.firePropertyChange("bairro", old, bairro);
    }

    public String getCidade() {
        return cidade;
    }

    public void setCidade(String cidade) {
        String old = this.cidade;
        this.cidade = cidade;
        changeSupport.firePropertyChange("cidade", old, cidade);
    }

    public String getCep() {
        return cep;
    }

    public void setCep(String cep) {
        String old = this.cep;
        this.cep = cep;
        changeSupport.firePropertyChange("cep", old, cep);
    }

    public Date getDataNascimento() {
        return dataNascimento;
    }

    public void setDataNascimento(Date dataNascimento) {
        Date old = this.dataNascimento;
        this.dataNascimento = dataNascimento;
        changeSupport.firePropertyChange("dataNascimento", old, dataNascimento);
    }

    public String getEstadoCivil() {
        return estadoCivil;
    }

    public void setEstadoCivil(String estadoCivil) {
        String old = this.estadoCivil;
        this.estadoCivil = estadoCivil;
        changeSupport.firePropertyChange("estadoCivil", old, estadoCivil);
    }

    public String getSexo() {
        return sexo;
    }

    public void setSexo(String sexo) {
        String old = this.sexo;
        this.sexo = sexo;
        changeSupport.firePropertyChange("sexo", old, sexo);
    }

    public String getTelefone() {
        return telefone;
    }

    public void setTelefone(String telefone) {
        String old = this.telefone;
        this.telefone = telefone;
        changeSupport.firePropertyChange("telefone", old, telefone);
    }

    public Collection<FuncaoPaciente> getFuncaoPacienteCollection() {
        return funcaoPacienteCollection;
    }

    public void setFuncaoPacienteCollection(Collection<FuncaoPaciente> funcaoPacienteCollection) {
        this.funcaoPacienteCollection = funcaoPacienteCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idPaciente != null ? idPaciente.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Paciente)) {
            return false;
        }
        Paciente other = (Paciente) object;
        if ((this.idPaciente == null && other.idPaciente != null) || (this.idPaciente != null && !this.idPaciente.equals(other.idPaciente))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "jpa.entities.Paciente[ idPaciente=" + idPaciente + " ]";
    }

    /**
     * A seguir, listeners para beanbinding
     */
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
}
